﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Mobile.Mvc;

namespace MVCDemoClient
{
    public partial class DetailForm : ViewForm, 
                             IView<NorthwindDataSet.ProductsRow>
    {      
        [PublishEvent("OnBack")]
        public event EventHandler OnBackEvent;
        
        public DetailForm()
        {
            InitializeComponent();
        }

        // Callback from the Controller
        private void OnProductLoaded(object sender, EventArgs e)
        {
            // Load the product details into controls
            this.txtProductID.DataBindings.Add("Text", 
                               this.ViewData.Model, "ProductID");
            this.txtProductName.DataBindings.Add("Text", 
                               this.ViewData.Model, "ProductName");
            this.txtUnitPrice.DataBindings.Add("Text", 
                               this.ViewData.Model, "UnitPrice");
            this.txtCategoryID.DataBindings.Add("Text", 
                               this.ViewData.Model, "CategoryID");
        }

        #region IView<NorthwindDataSet.ProductsRow> Members

        public new ViewDataDictionary<NorthwindDataSet.ProductsRow> ViewData
        {
            get;
            set;
        }

        public new NorthwindDataSet.ProductsRow Model
        {
            get;
            set;
        }

        #endregion

        #region event handlers

        private void menuItemBack_Click(object sender, EventArgs e)
        {
            if (OnBackEvent != null)
            {
                OnBackEvent(this, EventArgs.Empty);
            }
        }

        #endregion

       
    }
}